package com.leapp.sk.viewdelegate.task

import android.content.Intent
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.NoScrollGridView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.CompleteTaskEntity
import com.leapp.sk.ui.activity.task.CompleteTaskActivity
import com.leapp.sk.ui.adapter.CompleteTaskAdapter
/**
 *作业要求视图托管类
 * @author  chaohaipeng  on 2018/8/16.
 */
class TaskRequireDelegate:BaseAppDelegate() {
    /**
     * 适配器
     */
    private var voiceAdapter:CompleteTaskAdapter?=null
    override fun initWidget() {
    }
    override fun initLayoutRes(): Int {
        return R.layout.activity_task_require
    }
    /**
     * 初始化适配器
     */
    fun initAdapter(mlist: MutableList<CompleteTaskEntity>, isVoice:Boolean){
        val gv_atr_list = getView<NoScrollGridView>(R.id.gv_atr_list)
        voiceAdapter = CompleteTaskAdapter(getActivity(), mlist,true)
        gv_atr_list.adapter=voiceAdapter
        if (isVoice){
            gv_atr_list.numColumns=1
        }else{
            gv_atr_list.numColumns=3
        }
    }
    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val topBar= getView<SKTopBar>(R.id.jtb_atr_task_detial)
        if (!TextUtils.isEmpty(title)){
            topBar?.setTitle(title)
        }
        setEvent(topBar)
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar: SKTopBar){
        topBar.setRightTVContent(getActivity<AppCompatActivity>().resources.getString(R.string.string_task_complete))
        topBar.setRightTVColor(ContextCompat.getColor(getActivity<AppCompatActivity>(),R.color.color_19AD19))
        topBar.getTv_ljtb_right_back()?.visibility= View.VISIBLE
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<AppCompatActivity>().finish()
            }
            override fun rightOnClick() {
               val intent= Intent(getActivity<AppCompatActivity>(),CompleteTaskActivity::class.java)
                getActivity<AppCompatActivity>().startActivity(intent)
            }

        })
    }
}